<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="presentation.PresentationsBean"%>

<%@page import="com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH"%>
<%@page import="java.util.ArrayList"%><html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <%@page import="db.Album"%>
 <%@page import="db.Picture"%>
<%@page import="java.util.List"%>
<%@page import="presentation.Get16ImagesBean"%>   
<%@page import="presentation.Get16AlbumsBean"%> 
<%@page import="presentation.GetAllAlbumsBean"%>
<%@page import=" java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<head>
	<link rel="stylesheet" type="text/css" href="css/styleGallery.css" />  
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Пациент</title>
</head>

<body id="bd">

<div id="container">
	<my:header/>
	 <%   Integer pageNum =null;
	    try{
	 		 pageNum = Integer.parseInt(request.getParameter("page"));
		}catch( Exception e){  			
			pageNum=1;
		};   
	    GetAllAlbumsBean b = new GetAllAlbumsBean(pageNum);
	    
     	Long userid=(Long)session.getAttribute("userid");
     	List<Album> childAlbums = new ArrayList<Album>();
     	Long albumId = null;
     	long allALlNum = 0;
    	String aid = request.getParameter("album_id");
    	if (aid != null) {
     	albumId=Long.parseLong(aid);    	
     	childAlbums =b.get16CildAlbumsByParentId(albumId,pageNum);
     	List<Picture> pictures =b.getAllPictureByAlbum(albumId);
     	
       	allALlNum=b.get16ChildAlbumsNum(albumId);
    	}
       	List<Album> allExistAlbums =b.getAllExistAlbums();
   	  %>
   	  <%if (session.getAttribute("user")==null){ %>
		<my:menulogout/>
		<%}else{ %>
	<my:menulogin/>
<%} %>		

   		<%
   		String a = (String)request.getAttribute("a"); 
   		if (a == null) a = "no" ;
   		if (a.equals("all")) {
   			allExistAlbums =b.getAllExistAlbums();
   			if (allExistAlbums.isEmpty()) {
   		   		%>
   		   		<div id="midcontainer"> 
   		   			 <p id="err">Няма създадени пациенти до момента!</p>
   		   			 <div id="page">
   		   			 <li><a class="number" href="Home.jsp?album_id=<%=albumId %>"> &nbsp; Преглед на снимките<a></li>
   		   			 </div>
   		  		</div>
   		   		
   		   		<%}else{
   		   		%>
   		   		<div id="midcontainer">
   		   		<% 	
   		   		 	 for (Album album:allExistAlbums){%>
   		   		 	
   		          		 <div id ="pic">
   		            	 	 <li style=" display:inline;float:left;"><a href="ViewAlbum.jsp?album_id=<%=album.getAlbumId() %>"><img style="img-decoration:none; border-style:none;"src="img/folder_images.png"/></a></li>
   		            	 	 <li> <%=album.getAlbumName() %> </li>
   		             	 	<br>
   		             	 	<%if (session.getAttribute("user")!=null){ %>
   		            	 	  <li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
   		         		      <a href="EditAlbumServlet?album_id=<%=album.getAlbumId() %>" title="edit"><img style="img-decoration:none; border-style:none;" src="img/editFolder.png"/></a></li>
   		             	 	<li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
   		         	 	     <a href="DeleteAlbumServlet?album_id=<%=album.getAlbumId() %>" title="delete"><img style="img-decoration:none; border-style:none;" src="img/delFolder.png"/></a></li>
   		           		<%} %>
   		           		</div>        
   		   		   <%};%>
   		   
   		  			 <div id="page">
   		         <%
   		           if ((pageNum==1)&&(allALlNum>1)){ %>
   		              <li> Prev &nbsp;</li>		
   		   		      <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
   		          <%}else if( pageNum==allALlNum ){
   		        	 %>
   		             <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
   		   		     <li> <a class="number" href="Home.jsp?album_id=<%=albumId %>"> &nbsp; Next<a></li>		
   		          <%}else{ %>
   		  	        <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
   		  	        <%pageNum++;%>	
   		   		<li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
   		   		<%} %>
   		    </div>
   		    </div>
   		   		<%}
   		} else {
   		if (childAlbums.isEmpty()) {
   		%>
   		<div id="midcontainer"> 
   			 <p id="err">Няма създадени пациенти до момента!</p>
   			 <div id="page">
   			 <li><a class="number" href="Home.jsp?album_id=<%=albumId %>"> &nbsp; Преглед на снимките<a></li>
   			 </div>
  		</div>
   		
   		<%}else{
   		%>
   		<div id="midcontainer">
   		<% 	
   		 	 for (Album album:childAlbums){%>
   		 	
          		 <div id ="pic">
            	 	 <li style=" display:inline;float:left;"><a href="ViewAlbum.jsp?album_id=<%=album.getAlbumId() %>"><img style="img-decoration:none; border-style:none;"src="img/folder_images.png"/></a></li>
            	 	 <li> <%=album.getAlbumName() %> </li>
             	 	<br>
             	 	<%if (session.getAttribute("user")!=null){ %>
            	 	  <li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         		      <a href="EditAlbumServlet?album_id=<%=album.getAlbumId() %>" title="edit"><img style="img-decoration:none; border-style:none;" src="img/editFolder.png"/></a></li>
             	 	<li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         	 	     <a href="DeleteAlbumServlet?album_id=<%=album.getAlbumId() %>" title="delete"><img style="img-decoration:none; border-style:none;" src="img/delFolder.png"/></a></li>
           		<%} %>
           		</div>        
   		   <%};%>
   
  			 <div id="page">
         <%
           if ((pageNum==1)&&(allALlNum>1)){ %>
              <li> Prev &nbsp;</li>		
   		      <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
          <%}else if( pageNum==allALlNum ){
        	 %>
             <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
   		     <li> <a class="number" href="Home.jsp?album_id=<%=albumId %>"> &nbsp; Next<a></li>		
          <%}else{ %>
  	        <li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
  	        <%pageNum++;%>	
   		<li> <a class="number" href="ViewAlbum.jsp?album_id=<%=albumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
   		<%} %>
    </div></div>
   		<%}
   		}%>	
   		
<!-- midcontainer -->
<%b.releaseResources(); %>
<my:footer/>
</body>
</html>